#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 1e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int n, a, b;
int kk[N];
int xx[N];
int yy[N];
void solve()
{
	int ans=0x3f3f3f3f;
    cin >> n >> a >> b;

    for(int i = 1; i <= 2*n; i++)
    {
        if(i & 1)
        {
            int k, x, y;
            cin >> k >> x >> y;

            kk[i] = k;
            xx[i] = x;
            yy[i] = y;
        }
        else
        {
        	for(int j=1;j<=kk[i-1];j++)
        	{
        		int t;
        		cin>>t;
        		int cur=t;
        		if(t>=a) cur-=b;
        		if(t>=xx[i-1]) cur-=yy[i-1];
        		if(cur>=0) ans=min(ans,cur);
        		else ans=min(0,ans);
        	}
        }
    }

   	cout<<ans<<'\n';

    }

int main()
{
    close();
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}